<?
require_once( 'image-resizer-0-base.php' );

class PhpThumbImageResizer extends ImageResizer 
{
	var $filesToInclude = array();
	function PhpThumbImageResizer( $phpThumbPath )
	{
		/*
		if ( is_dir( $phpThumbPath) )
		{
		 	$phpThumbPath = $this->Controller->pathNormalize( $phpThumbPath );
		 	
		}
		*/
		$this->filesToInclude[] = $phpThumbPath;
	}
	function _acceptRequest()
	{
		$result = parent::_acceptRequest();
		if ( ! $result ) return $result;
		foreach ( $this->filesToInclude as $file )
		{
			if ( !file_exists( $file ))
			{
				$this->log( 'File to be included "'.$file.'" not found. Driver de-activated, current request refused.' );
				return null;
			}
		}
		foreach ( $this->filesToInclude as $file )
		{
			include( $file );
		}
		return  true;
	}
	function renderContent ( $source, $destination, $w, $h )
	{
		$phpThumb = new phpThumb();
		// set data
		$phpThumb->setSourceFilename( $source );
		// set parameters (see "URL Parameters" in phpthumb.readme.txt)
		if ( $w ) $phpThumb->setParameter('w', $w );
		if ( $h ) $phpThumb->setParameter('h', $h );
		// generate & output thumbnail
		if ($phpThumb->GenerateThumbnail()) { // this line is VERY important, do not remove it!
			if ($phpThumb->RenderToFile( $destination )) {
				// do something on success
				$this->log( 'renderImage - Successfully rendered to "'.$destination.'"' );
				return true;
			} else {
				// do something with debug/error messages
				$this->log( 'renderImage - Failed:'."\n".implode("\n\n", $phpThumb->debugmessages) );
				return false;
			}
		} else {
			// do something with debug/error messages
			$this->log( 'renderImage - Failed:'."\n".$phpThumb->fatalerror."\n\n".implode("\n\n", $phpThumb->debugmessages) );
			return false;
		}
	}
}
?>